<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<style>
a:link{text-decoration:none;}
a:visited{text-decoration:none;}
a:hover{text-decoration:underline;}
a:active{text-decoration:none;}
</style>
<html>
<head>
	<jsp:include page="/include.jsp"/>
	<script type="text/javascript">
	$(function()
	{
		initDatagrid();
		
		//指标名称
		$('#dqm_accuracyruleconf_kqiidselectlist').combogrid({
			url: '${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getAllKqiName.action',
			panelWidth: 550,
			panelHeight:300,
			mode: 'remote',
			idField: 'kqiid',
			pagination:true,
			pageList: [10,20,30],
			textField: 'kqiname',
			required: true,
			fit:true,
			border:false,
			editable:false,
			sortName:'createtime',
			sortOrder:'desc',
			columns: [[
						{field:'kqiid',title:'指标编码',width:55},
						{field:'kqiname',title:'指标名称',width:75,formatter:function(value,rowData,rowIndex){
							return '<span title="'+value+'">'+value+'<span>';
						}},
						{field:'kqisql',title:'指标sql',width:395,formatter:function(value,rowData,rowIndex){
							return '<span title="'+value+'">'+value+'<span>';
						}},
					]],
			toolbar:'#dqm_accuracyruleconf_kqiidselecttoolbarlist',
			onLoadSuccess:function(){
				var sqlDiv=$("td[field='kqisql'] div");//如果kqisql的内容太长，则由...代替
				sqlDiv.css({
					"white-space":"nowrap",
					"text-overflow":"ellipsis",
					"-o-text-overflow":"ellipsis",
					"overflow":"hidden"
				});
				var kqiNameDiv=$("td[field='kqiname'] div");//如果kqiName的内容太长，则由...代替
				kqiNameDiv.css({
					"white-space":"nowrap",
					"text-overflow":"ellipsis",
					"-o-text-overflow":"ellipsis",
					"overflow":"hidden"
				});
				$('#dqm_accuracyruleconf_kqiidselectlist').combogrid('setText','全部');
			}
		});
		
		//规则算法
		$('#dqm_accuracyruleconf_rulealgorithmselectlist').combobox({  
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=ruleAlgorithm&method=list',  
			valueField:'codeValue',
			textField:'codeName',
			editable:false,
			required: false,
			onLoadSuccess:function(){
				//不让第一条为默认选择项
				$('#dqm_accuracyruleconf_rulealgorithmselectlist').combobox('unselect',0);
				$('#dqm_accuracyruleconf_rulealgorithmselectlist').combobox('setValue',null);
			}
		});
		//告警级别
		$('#dqm_accuracyruleconf_warnlevelselectlist').combobox({
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=warnLevel&method=list',  
			valueField:'codeValue',
			textField:'codeName',
			editable:false,
			required: false,
			onLoadSuccess:function(){
				//不让第一条为默认选择项
				$('#dqm_accuracyruleconf_warnlevelselectlist').combobox('unselect',0);
				$('#dqm_accuracyruleconf_warnlevelselectlist').combobox('setValue',null);
			}
		});
		//==================================================================================
		//指标名称下拉datagrid中的下拉列表
		//指标周期类型
		$.ajax({
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=periodType&method=list',
			dataType:'json',
			success:function(result){
				var periodtypeSelect=document.getElementById("dqm_accuracyruleconf_periodtypecombogridselectlist");
				for(var i=0;i<result.length;i++)
				{
					var opt=new Option();
					opt.value=result[i].codeValue;
					opt.text=result[i].codeName;
					periodtypeSelect.add(opt);
				}
			}
		});
		//数据提取层
		$.ajax({
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=dataLevel&method=list',
			dataType:'json',
			success:function(result){
				var dataLevelSelect=document.getElementById("dqm_accuracyruleconf_dataLevelcombogridselectlist");
				for(var i=0;i<result.length;i++)
				{
					var opt=new Option();
					opt.value=result[i].codeValue;
					opt.text=result[i].codeName;
					dataLevelSelect.add(opt);
				}
			}
		});
		
	});
	
	//重置查询条件
	function doReset()
	{
		$('#dqm_accuracyruleconf_rulenameinputlist').val('');
		$('#dqm_accuracyruleconf_creatorinputlist').val('');
		$('#dqm_accuracyruleconf_kqiidselectlist').combogrid('setText','全部');
		$('#dqm_accuracyruleconf_rulealgorithmselectlist').combobox('setValue',null);
		$('#dqm_accuracyruleconf_warnlevelselectlist').combobox('setValue',null);
	}
	
	function initDatagrid()
	{
		$('#dqm_accuracyruleconf_rulelisttab').datagrid({
			url : '${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getAllAccuracyRuleConf.action',
			fit:true,
			border:false,
			fitColumns:true,
			pagination:true,
			striped:true,
			pageList:[10,20,30],
			singleSelect:false,
			pagePosition:'bottom',
			autoRowHeight:true,
			sortName:'createtime',
			sortOrder:'desc',
			columns:[[  {field:'ck',checkbox:true},
			            {field:'ruleId',title:'规则编码',width:70,align:'center',sortable:true},
			            {field:'ruleName',title:'规则名称',width:120,align:'left',sortable:true,formatter:function(value,rowData,rowIndex){
			                return '<a title="'+rowData.ruleName+'" onclick="doDetail('+rowData.ruleId+')"  style="color:#2b76b7;cursor:pointer;">'+rowData.ruleName+'</a>';
			            }},
			            {field:'ruleVersionNum',title:'版本号',width:40},
						{field:'ruleTypeName',title:'规则类型',width:60,align:'center',sortable:false},
						{field:'ruleAlgorithmName',title:'规则算法',width:140,align:'center',sortable:false},
						{field:'kqiName',title:'指标名称',width:100,align:'left',sortable:true,formatter:function(value,rowData,rowIndex){
							return '<span title="'+value+'">'+value+'<span>';
						}},
						{field:'warnLevelName',title:'告警级别',width:60,align:'center',sortable:false,},
						{field:'thresholdMax',title:'阀值上限',width:60,align:'right',sortable:true},
						{field:'thresholdMin',title:'阀值下限',width:60,align:'right',sortable:true},
						{field:'creator',title:'创建者',width:80,align:'center',sortable:true},
						{field:'dsafd',title:'操作',width:160,align:'left',formatter:function(value,rowData,rowIndex){
							return '<span  style="cursor:pointer" onclick="doEdit('+rowData.ruleId+','+rowData.ruleVersionNum+')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="修改" alt="修改" style="margin-top:2px;"/>修改&nbsp;&nbsp;</span>'
							      +'<span  style="cursor:pointer" onclick="doDelete('+rowData.ruleId+','+rowData.ruleVersionNum+')"><img src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除" style="margin-top:2px;"/>删除&nbsp;&nbsp;</span>';
						}}
					]],
			toolbar:'#dqm_accuracyruleconf_rulelisttoobar',
			onLoadSuccess:function(){
				var ruleNameDiv=$("td[field='ruleName'] div");//如果ruleName的内容太长，则由...代替
				var kqiNameDiv=$("td[field='kqiName'] div");//如果kqiName的内容太长，则由...代替
				ruleNameDiv.css({
					"white-space":"nowrap",
					"text-overflow":"ellipsis",
					"-o-text-overflow":"ellipsis",
					"overflow":"hidden"
				});
				kqiNameDiv.css({
					"white-space":"nowrap",
					"text-overflow":"ellipsis",
					"-o-text-overflow":"ellipsis",
					"overflow":"hidden"
				});
			}
		});
	}

	//查询Kqi信息
	function queryKqi()
	{
		var kqiNameForComboGrid=$('#dqm_accuracyruleconf_kqinamecombogridinputlist').val();
		var periodType=$('#dqm_accuracyruleconf_periodtypecombogridselectlist').val();
		if(periodType=='undefined')
		{
			periodType=null;
		}
		var dataLevel=$('#dqm_accuracyruleconf_dataLevelcombogridselectlist').val();
		if(dataLevel=='undefined')
		{
			dataLevel=null;
		}
		var query={kqiNameForComboGrid:kqiNameForComboGrid,periodType:periodType,dataLevel:dataLevel};
		var grid=$('#dqm_accuracyruleconf_kqiidselectlist').combogrid('grid');
		$(grid).datagrid('options').queryParams=query;
		$(grid).datagrid('load');
	}
	//重置kqi查询条件
	function doResetQueryKqi()
	{
		$('#dqm_accuracyruleconf_kqinamecombogridinputlist').val('');
		var periodtypeOptions=document.getElementById("dqm_accuracyruleconf_periodtypecombogridselectlist").options;
		var periodtypeLength=periodtypeOptions.length;
		for(var i=0;i<periodtypeLength;i++)
		{
			if(periodtypeOptions[i].text=='全部')
			{
				periodtypeOptions[i].selected=true;
			}
		}
		
		var dataLevelOptions=document.getElementById("dqm_accuracyruleconf_dataLevelcombogridselectlist").options;
		var dataLevelLength=dataLevelOptions.length;
		for(var i=0;i<dataLevelLength;i++)
		{
			if(dataLevelOptions[i].text=='全部')
			{
				dataLevelOptions[i].selected=true;
			}
		}
	}
	//分页查询
	function doQuery()
	{
		var dataGridOptions=$('#dqm_accuracyruleconf_rulelisttab').datagrid('options');
		if($('#dqm_accuracyruleconf_searchform').form('validate'))
		{
			dataGridOptions.queryParams=serializeObject($('#dqm_accuracyruleconf_searchform'));
			$('#dqm_accuracyruleconf_rulelisttab').datagrid(dataGridOptions);
			$('#dqm_accuracyruleconf_rulelisttab').datagrid('load');
		}
	}
	
	//添加
	function doAdd() 
	{
		window.top.$('<div id="dqm_accuracyruleconf_adddialog"/>').dialog({
			href : '${pageContext.request.contextPath}/dqm/basemgr/ruleconfig/accuracyruleconf_add.jsp',
			top:($(window.top).height()-550)*0.5,
			left:($(window.top).width()-900)*0.5,
			width:1000,
			modal : true,
			title : '新增准确性规则',
			onClose : function() {
				$('#dqm_accuracyruleconf_rulelisttab').datagrid('reload');
				window.top.$(this).dialog('destroy');
			}
		});
	}
	
	//详细
	function doDetail(ruleId)
	{
		window.top.$('<div id="dqm_accuracyruleconf_detaildialog"/>').dialog({
			href:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!detailAccuracyRuleConf.action?ruleId='+ruleId,
			top:($(window.top).height()-550)*0.5,
			left:($(window.top).width()-900)*0.5,
			width:1000,
			modal:true,
			title:'规则详细信息',
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
	}
	
	//修改
	function doEdit(ruleId,ruleVersionNum)
	{
		var modifyAll="1";
		$.ajax({
			   url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!checkInUse.action',
			   dataType:'json',
			   data:{ruleId:ruleId,ruleVersionNum:ruleVersionNum},
			   success:function(data){
				 	if(data.returnFlag){
				 		modifyAll="2";//如果正在被使用，只能修改部分配置
				 		window.top.$.messager.confirm('修改提示', '该规则正在被使用，只能修改部分配置', function(r){
				 			if(r)
				 			{
								window.top.$('<div id="dqm_accuracyruleconf_editdialog"/>').dialog({
									href:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!toModifyAccuracyRuleConf.action?ruleId='+ruleId+'&modifyAll='+modifyAll,
									top:($(window.top).height()-550)*0.5,
									left:($(window.top).width()-900)*0.5,
									width:1000,
									modal:true,
									title:'修改准确性规则',
									onClose:function(){
										$('#dqm_accuracyruleconf_rulelisttab').datagrid('reload');
										window.top.$(this).dialog('destroy');
										}
									});
				 			}
				 		});
				 	}else{//可以全部修改
						window.top.$('<div id="dqm_accuracyruleconf_editdialog"/>').dialog({
							href:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!toModifyAccuracyRuleConf.action?ruleId='+ruleId+'&modifyAll='+modifyAll,
							top:($(window.top).height()-550)*0.5,
							left:($(window.top).width()-900)*0.5,
							width:1000,
							modal:true,
							title:'修改准确性规则',
							onClose:function(){
								$('#dqm_accuracyruleconf_rulelisttab').datagrid('reload');
								window.top.$(this).dialog('destroy');
								}
							});
					}
				}
			});	
		}
	
	//删除
	function doDelete(ruleId,ruleVersionNum)
	{
		$.ajax({
			   url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!checkInUse.action',
			   dataType:'json',
			   data:{ruleId:ruleId,ruleVersionNum:ruleVersionNum},
			   success:function(data){
				 	if(data.returnFlag){
				 		$.messager.show({
							title:'操作提示',
							msg:data.returnMsg
						});
				 	}else{
						window.top.$.messager.confirm('删除确认', '确定要删除该条记录吗？', function(r){
							if (r){
									$('#dqm_accuracyruleconf_searchform').form('submit',{
									url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!deleteAccuracyRuleConf.action?ruleId='+ruleId,
									success:function(result){
										try {
											var r = $.parseJSON(result);
											$.messager.show({
												title : '提示',
												msg : r.returnMsg
											});
											if (r.returnFlag) {
												$('#dqm_accuracyruleconf_rulelisttab').datagrid('reload');
											}
										} catch (e) {
											window.top.$.messager.alert('提示', result);
										}
									}
								});
							}
						});
					}
				}
			}); 
	}
	
	//批量删除
	function doBatchDelete()
	{
		var rows=$('#dqm_accuracyruleconf_rulelisttab').datagrid('getChecked')
		if(rows.length<=0){
			window.top.$.messager.alert('提示','没有选择任何记录');
		}else{
			var checks = new Object();
			checks["checkedRows"]=JSON.stringify(rows);
			$.post(
					"${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!checkInUse.action",
					checks,
					function(rsp){
						if (rsp.returnFlag) {
					 		$.messager.show({
								title:'操作提示',
								msg:rsp.returnMsg
							});
						}else{
							window.top.$.messager.confirm('删除确认', '确定要删除所选择的记录吗？', function(r){
								if (r){
										$('#dqm_accuracyruleconf_searchform').form('submit',{
										url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!batchDeleteAccuracyRuleConf.action',
										success:function(result){
											try {
												var r = $.parseJSON(result);
												$.messager.show({
													title : '提示',
													msg : r.returnMsg
												});
												if (r.returnFlag) {
													$('#dqm_accuracyruleconf_rulelisttab').datagrid('reload');
												}
											} catch (e) {
												window.top.$.messager.alert('提示', result);
											}
										}
									});
								}
							});
						}
					},
					"json"
				);
		}
	}
	</script>
</head>

<body class="easyui-layout" id="body">
<form id="dqm_accuracyruleconf_searchform" method="post">
	<div data-options="region:'north'" style="height:80px;border-bottom:none;border-top:none;">
	<table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" >
			<tr>
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label>规则名称：</label>
				</td>
				<td style="text-align:left;width:15%;" nowrap="nowrap">
					<input id="dqm_accuracyruleconf_rulenameinputlist" type="text" name="ruleName" validType="specialCharFilter('dqm_accuracyruleconf_rulenameinputlist')" class="easyui-validatebox"></input> 
				</td>
				
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label>指标名称：</label>
				</td>
				<td style="text-align:left;width:15%;" nowrap="nowrap">
					<input id="dqm_accuracyruleconf_kqiidselectlist" type="text" name="kqiId" panelHeight="auto"></input>
				</td>
				
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label>规则算法：</label>
				</td>
				<td style="text-align:left;width:15%;" nowrap="nowrap">
					<input id="dqm_accuracyruleconf_rulealgorithmselectlist" type="text" name="ruleAlgorithm" panelHeight="auto"/>
				</td>
				
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label>告警级别：</label>
				</td>
				<td style="text-align:left;width:15%;padding-right:35px;" nowrap="nowrap">
					<input id="dqm_accuracyruleconf_warnlevelselectlist" type="text" name="warnLevel" panelHeight="auto"/>
				</td>
			</tr>
			
			<tr>
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label>创建者：</label>
				</td>
				<td style="text-align:left;width:15%;" nowrap="nowrap">
					<input id="dqm_accuracyruleconf_creatorinputlist" type="text" name="creator" class="easyui-validatebox" validType="specialCharFilter('dqm_accuracyruleconf_creatorinputlist')"></input>
				</td>
				<td style="width:10%;text-align:right;" nowrap="nowrap">
				</td>
				<td style="width:15%;text-align:left;" nowrap="nowrap">
				</td>
				<td style="width:10%;text-align:right;" nowrap="nowrap">
				</td>
				<td style="width:15%;text-align:left;" nowrap="nowrap">
				</td>
				<td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap">
					<input type="button"  onclick="doQuery()" value="查询" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑"/>	
					<input type="button"  onclick="doReset()" value="重置" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:35px"/>			
				</td>
			</tr>
	</table>
	</div>
	
	<div data-options="region:'center'" style="border-top:none">
		<table id="dqm_accuracyruleconf_rulelisttab"></table>
		
		<div id="dqm_accuracyruleconf_rulelisttoobar" class="etl_panel_title">
			<a href="javascript:void(0);"  onclick="doAdd()" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="float:left">新增</a>
			<div class="datagrid-btn-separator"></div>
			<a href="javascript:void(0);" onclick="doBatchDelete()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">批量删除</a>
		</div>
	</div>
	
	
		<!--指标名称combogrid的查询条件的toolbar-->
	<div id="dqm_accuracyruleconf_kqiidselecttoolbarlist" style="padding:5px;height:auto">
	<div id="dqm_accuracyruleconf_querykqidivlist" >
			<table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" >
			<tr height="40px">
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label>指标名称：</label>
				</td>
				<td style="text-align:left;width:15%;" nowrap="nowrap">
					<input id="dqm_accuracyruleconf_kqinamecombogridinputlist" name="kqiNameForComboGrid" type="text"/>
				</td>
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label>周期类型：</label>
				</td>
				<td style="text-align:left;width:15%;padding-right:25px;" nowrap="nowrap">
					<select id="dqm_accuracyruleconf_periodtypecombogridselectlist" name="periodType" style="width:162px;height:22px;">
					</select>
				</td>
			</tr>
			<tr height="40px">
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label>数据提取层：</label>
				</td>
				<td style="text-align:left;width:15%;padding-right:35px" nowrap="nowrap">
					<select id="dqm_accuracyruleconf_dataLevelcombogridselectlist" name="dataLevel" style="width:162px;height:22px;">
					</select>
				</td>
				<td style="width:10%;text-align:right;" nowrap="nowrap">
				</td>
				<td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap">
					<input type="button" onclick="queryKqi()" value="查询" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑"/>	
					<input type="button" onclick="doResetQueryKqi()" value="重置" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:35px"/>						
				</td>
			</tr>
			</table>
	</div>
	</div>
	</form>
</body>
</html>
